package suites.tween {
	import org.splink.library.draw.shape.CircleShape;
	import org.splink.library.draw.shape.RectShape;
	import org.splink.library.draw.style.FillStyle;
	import org.splink.library.queue.QEvent;
	import org.splink.library.tween.IQTween;
	import org.splink.library.tween.QTween;
	import org.splink.library.tween.sprop.ColorProp;
	import org.splink.library.tween.sprop.ISpecialProp;
	import org.splink.library.utils.PerformanceMeasure;

	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.BlurFilter;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	/**
	 * @author Max Kugland
	 */
	public class VisualQTweenTest extends Sprite {
		private var _btn : Sprite;

		public function VisualQTweenTest() {
			
			for (var i : int = 0;i < 100;i++) {
				var s : Shape = new CircleShape(new Point(2, 2), 4, new FillStyle(Math.random() * 9999999));
				createSketch(addChild(s));
			}
			
			testBtn();
			addChild(new PerformanceMeasure());
		}

		private function createSketch(s : DisplayObject) : void {
			var scale : Number = Math.random();
			var sketch : IQTween = new QTween(s, s.name);
			sketch.add("color", Math.random() * 9999999, NaN, new ColorProp(s));
			sketch.add("scaleX", scale);			sketch.add("scaleY", scale);
			sketch.add("x", Math.random() * 550);
			sketch.add("y", Math.random() * 400);
			sketch.duration(500 + Math.random() * 1000).delay(400);
			sketch.register(QEvent.COMPLETE, function(e : QEvent):void {
				createSketch(s);
			});
			sketch.start();
		}

		private function testBtn() : void {
			_btn = new Sprite();
			_btn.addChild(new RectShape(new Rectangle(0, 0, 50, 50), new FillStyle()));
			_btn.addEventListener(MouseEvent.MOUSE_OVER, over);
			_btn.addEventListener(MouseEvent.MOUSE_OUT, out);
			addChild(_btn).filters = [new BlurFilter(0, 0)];
			_btn.y = 200;
		}

		private function out(event : MouseEvent) : void {
			var cp : ISpecialProp = new ColorProp(_btn);			
			new QTween(_btn).add("width", 50).add("color", Math.random() * 999999, NaN, cp).duration(1000).start();
		}

		private function over(event : MouseEvent) : void {
			var cp : ISpecialProp = new ColorProp(_btn);
			
			new QTween(_btn).add("width", 550).add("color", Math.random() * 999999, NaN, cp).duration(1000).start();
		}
	}
}
